package com.strom.eventbus;

import com.google.common.eventbus.*;
import lombok.AllArgsConstructor;
import lombok.Data;

public class EventBusSimpleDemo {

    @Data
    @AllArgsConstructor
    private static class Event{

        private String msg;
    }

    private static class EventHandler {


        @AllowConcurrentEvents
        @Subscribe
        private void handle(Event event) {
            System.out.println("handle:" + event);
        }

        @AllowConcurrentEvents
        @Subscribe
        private void handle(String event) {
            System.out.println("handle:" + event);
        }
    }

    public static void main(String[] args) {
        // 可以封装成单列模式
        EventBus eventBus = new EventBus("strom");
        // 注册
        eventBus.register(new EventHandler());
        // 发送时间
       eventBus.post(new Event("aaa"));
       eventBus.post("aaa");

        System.out.println(eventBus.identifier());

        eventBus.unregister(new EventHandler());
    }
}
